package br.com.lambdacore.iterator;

import java.util.Iterator;
import java.util.NoSuchElementException;

public class CharRange implements Iterable<Character>, Iterator<Character> {

	private final char end;
	private char current;

	public CharRange(char start, char end) {
		this.current = start;
		this.end = end;
	}

	public boolean hasNext() {
		return this.current <= this.end;
	}

	public Iterator<Character> iterator() {
		return this;
	}

	public Character next() {
		if (!this.hasNext()) {
			throw new NoSuchElementException();
		}
		char ret = this.current;
		this.current++;
		return ret;
	}

	public void remove() {
		throw new UnsupportedOperationException("Not supported operation");
	}

	public static Iterable<Character> range(char end) {
		return range(Character.MIN_VALUE, end);
	}

	public static Iterable<Character> range(char start, char end) {
		return new CharRange(start, end);
	}

}
